package com.accp.vehiclecare.biz.syhbiz;

import com.accp.vehiclecare.dao.syhdao.RepairbillMapper;
import com.accp.vehiclecare.pojo.Repairbill;
import com.accp.vehiclecare.vo.syhvo.DetailedVo;
import com.accp.vehiclecare.vo.syhvo.RepairbillVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class RepairbillBiz {

    @Resource
    private RepairbillMapper dao;

    public PageInfo<RepairbillVO> queryAll(Integer p, Integer s,Integer zt){
        PageHelper.startPage(p,s);
        return new PageInfo<RepairbillVO>(dao.selectRepairbill(zt));
    }

    public DetailedVo queryOne(Integer id){
        return dao.selectOne(id);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public boolean addRepairbill(Repairbill repairbill){
        if(repairbill.getRepairbilldate() == null){
            repairbill.setRepairbilldate(new Date());
        }
        if(repairbill.getRepairbilldates() == null){
            repairbill.setRepairbilldated(new Date());
        }
        return dao.insertSelective(repairbill) > 0;
    }


    @Transactional(propagation = Propagation.REQUIRED)
    public void modifyZt(String billNo,Integer zt){
        dao.updateZt(billNo, zt,new Date());
    }
}
